package TeacherEvaluation.com.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import TeacherEvaluation.com.dao.departmentDao;
import TeacherEvaluation.com.entity.Department;
/**
 * 
 * @author 陈龙
 *院系server类
 */
@Service
public class departmentService {
	//获取bean
	@Autowired
	departmentDao departmentDao;
	
	//添加院系
	public int insertDep(String department) {
		//查看院系是否存在，如果存在返回0，如果存在插入院系
		int i = departmentDao.selectDepByName(department);
		if(i>0) {
			return 0;
		}else {
			return departmentDao.insertDep(department);
		}
	};
	
	//查看所有院系
	public List<Department> selectDep(){
		return departmentDao.selectDep();
	};
	
	//修改院系
	public int updateDep(Department department) {
		//查看院系是否存在，如果存在返回0，如果不存在修改院系
		int i = departmentDao.selectDepByName(department.getDepartment());
		if(i>0) {
			return 0;
		}else {
			return departmentDao.updateDep(department);
		}
	};
	
	//删除院系
	public int deleDep(int dep_id) {
		int i = departmentDao.deleDep(dep_id);
		if(i==0) {
			return 0;
		}else {
			return i;
		}
	}
}
